<template>
  <div class="consulting">
    <el-main>
        <el-tabs v-model="activeIndex" @tab-click="handleClick">
          <el-tab-pane label="全部" >
              <ConsultingItem @chat="chat" @save="save" :activeIndex="activeIndex" @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"  :list = "list" :page="page"/>
          </el-tab-pane>
          <el-tab-pane label="专利保险" >
                        <ConsultingItem  @chat="chat" @save="save"  :activeIndex="activeIndex" @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"  :list = "list" :page="page"/>
          </el-tab-pane>
          <el-tab-pane label="职称考试" >
                        <ConsultingItem  @chat="chat" @save="save"  :activeIndex="activeIndex" @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"  :list = "list" :page="page"/>
          </el-tab-pane>

          <el-tab-pane label="政策咨询" >
            <ConsultingItem  @chat="chat" @save="save"  :activeIndex="activeIndex" @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"  :list = "list" :page="page"/>
          </el-tab-pane>
          <el-tab-pane label="产学合作" >
            <ConsultingItem  @chat="chat" @save="save"  :activeIndex="activeIndex" @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"  :list = "list" :page="page"/>
          </el-tab-pane>
        </el-tabs>
    </el-main>
    <ConsultingItem/>
     <Service />
  </div>
</template>


<script>
    import {userSave,frontendContent} from "@/api/user"
import Service from "@/components/Service";

    import ConsultingItem from '@/components/ConsultingItem'
    export default {
      components:{
        ConsultingItem,
        Service
      },
      data() {
        return {
          activeIndex:0,
          list:[],
          textarea:'',
          textShow:true,
          page:[],
          size:null,
          state:false,
        };
      },

      mounted() {
        this.getdata();
      },
      methods: {
        handleClick(tab, event) {
          this.activeIndex = tab.index
          this.getdata();
        },
        async getdata(){
          try{
            const res = await frontendContent({
              cid:this.activeIndex,
              size:this.size,
            })
            this.list = res.list;
            this.page = res.page;
          } catch(e){
            this.$message.error(e.message)
          }
        },
        async save(id,textarea){
          try{
            await userSave({
              id:id,
              user_desc:textarea
            })
            this.textShow = false
            this.getdata()
            this.$message.success("保存成功")
          } catch (e){
            this.$message.error(e.message)
          }
        },
        chat(val){
          if(val){
            this.getdata();
          }
        },
        //每页下拉显示数据
        async handleSizeChange(size,index) {
          this.size = size;
          this.activeIndex =index
          this.getdata()
           document.documentElement.scrollTop = 0
        },
        //点击第几页
        async handleCurrentChange(currentPage,index) {
          this.size = currentPage;
          this.activeIndex =index
           this.getdata()
            document.documentElement.scrollTop = 0
        },
      }
    };
</script>
